using System.Threading;

namespace RoMBot.Classes
{
    public sealed class EquipmentItem : Item
    {
        public EquipmentItem( int slotNumber )
            : base( slotNumber )
        {
            this.Location = "equipment";
            this.SlotNumber = slotNumber;
            this.BagId = slotNumber;

            if ( this.SlotNumber != 0 )
            {
                this.Update();
            }
        }

        public override void Update()
        {
            this.Address = Addresses.staticEquipBase + ( this.BagId * 68 );
            base.Update();
        }

        public void Use()
        {
            this.Update();
            if ( this.Empty )
            {
                return;
            }

            if ( this.InUse )
            {
                return;
            }

            Helpers.RoMScript( "UseEquipmentItem(" + this.BagId + ")" );
            Thread.CurrentThread.Join( 500 );
        }

        public int DurabilityPercent
        {
            get { return ( int ) ( this.MaxDurability > 0 ? this.Durability / this.MaxDurability * 100f : 0 ); }
        }

        public override string ToString()
        {
            return string.Format( "Name: {0}, Slot: {1}, Durability: {2}, MaxDurability: {3}, DurabilityPercent: {4}", Name, SlotNumber, Durability, MaxDurability, DurabilityPercent );
        }
    }
}
